#ifndef ENTITYCAMERA_H
#define ENTITYCAMERA_H
#include "Vector3.h"
#include "../AvatarLibrary.h"

class EntityCamera
{
public:
    // 相机类型枚举
    enum class CameraType { DEFAULT, SMOOTH, FREE, GAZE, VIEWER, GEOGRAPHIC };

    // 相机类型
    CameraType Type;

    // 相机位置
    Vector3 Position;

    // 相机方向
    Vector3 Angle;

    // 相机目标
    Vector3 Target;

    // 相机FOV
    float FieldOfView;

    // 近裁剪面
    float ClipNear;

    // 远裁剪面
    float ClipFar;

    /**
     * @brief 构造函数
     */
    EntityCamera()
    {
        Type = CameraType::SMOOTH;
        Position = Vector3(0.0f, 0.0f, 0.0f);
        Angle = Vector3(0.0f, 0.0f, 0.0f);
        Target = Vector3(0.0f, 0.0f, 0.0f);
        FieldOfView = 60.0f;
        ClipNear = 0.2f;
        ClipFar = 2000.0f;
    }

    /**
     * @brief 更新方位
     */
    void Update()
    {
        AvatarLibrary::avatar_camera_position(Position);
        AvatarLibrary::avatar_camera_angle(Angle);
        AvatarLibrary::avatar_camera_target(Target);
    }

    /**
     * @brief 获取脚本代码
     * @param prefix
     * @return
     */
    QString Script(const QString& prefix = "")
    {
        QStringList command;
        command.append(prefix + QString("camera.type('%1')").arg(ToString()));
        command.append(prefix + QString("camera.fov(%1)").arg(FieldOfView));
        command.append(prefix + QString("camera.clip(%1,%2)").arg(ClipNear).arg(ClipFar));
        command.append(prefix + QString("camera.target(%1)").arg(Target.ToString()));
        command.append(prefix + QString("camera.position(%1)").arg(Position.ToString()));
        command.append(prefix + QString("camera.angle(%1)").arg(Angle.ToString()));
        return command.join('\n');
    }

    /**
     * @brief 解析字符串
     * @param type
     */
    void Parse(const QString& type)
    {
        if (type == "default") Type = CameraType::DEFAULT;
        else if (type == "smooth") Type = CameraType::SMOOTH;
        else if (type == "free") Type = CameraType::FREE;
        else if (type == "gaze") Type = CameraType::GAZE;
        else if (type == "viewer") Type = CameraType::VIEWER;
        else if (type == "geographic") Type = CameraType::GEOGRAPHIC;
    }

    /**
     * @brief 重载 ToString
     * @return
     */
    QString ToString() const
    {
        switch (Type)
        {
        case CameraType::DEFAULT: return "default";
        case CameraType::SMOOTH: return "smooth";
        case CameraType::FREE: return "free";
        case CameraType::GAZE: return "gaze";
        case CameraType::VIEWER: return "viewer";
        case CameraType::GEOGRAPHIC: return "geographic";
        default: return "";
        }
    }
};

#endif // ENTITYCAMERA_H
